<?php
session_start();

require_once 'includes/includes.php';

$ArUrl = TreatUrl();
$StController = !empty($ArUrl['Controller']) ? $ArUrl['Controller'] : DEFAULT_CONTROLLER_INDEX ;
$StAction = !empty($ArUrl['Action']) ? $ArUrl['Action'] : DEFAULT_ACTION_INDEX ;
$StAction = replaceUrlFriendlyToAction($StAction);
$StControllerClass = ucfirst($StController) . 'Controller';
require_once DRA_CONTROLLER_PATH . $StController . '.controller.php';

$app = new $StControllerClass();
try {
    $app->init();
    $app->validateUser();
    $app->validate();
    $app->$StAction();
} catch(UserNotLoggedException $e) {
    redirect('login');
} catch(PermissionDeniedException $e) {
    $app->permissionDenied( $e->getMessage() );
}
$app->commit();

?>